import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.util.Enumeration;

/**
 * User: breedish
 */
public class LoginController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Writer output = resp.getWriter();
        output.append("<html>");
        output.append("<body>");
        final Enumeration<String> parameterNames = req.getParameterNames();
        if (parameterNames.hasMoreElements()) {
            output.append("<div>");
            int index = 1;
            while(parameterNames.hasMoreElements()) {
                String parameterName = parameterNames.nextElement();
                String value = req.getParameter(parameterName);
                output.append(String.format("<div style=\"color:blue\">%s. Parameter %s = %s</div>", String.valueOf(index), parameterName, value));
                index++;
            }
            output.append("</div>");
            output.append("<div><a href=\"/login_app\">Back to login page</a></div>");
        } else {
            output.append("<div>No request parameters were specified!</div>");
        }

        output.append("</body>");
    }
}
